import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class lever here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class lever  extends Actor
{
    GreenfootImage buffer = new GreenfootImage(6,10);
    boolean right,hit=false;
    
    public lever (boolean r){
        right=r;     
    }
    
    protected void addedToWorld(World world)
    {
        setImage(buffer);
        buffer.drawImage(((it) getWorld()).getLever(),0,0);  
        if(!right)buffer.mirrorHorizontally();
    } 
    
    public void act() 
    {
        Actor it = getOneIntersectingObject(Zony.class);
        Actor it2 = getOneIntersectingObject(sword.class);
        if((it!=null || it2!=null)&& !hit){
            Greenfoot.playSound("switch.wav");
            hit=true;
            buffer.mirrorVertically();
            ((it) getWorld()).open();
            door d;
            if(((it) getWorld()).openFull()){
                  Greenfoot.playSound("door.wav");
                  for(int f=0;f<getWorld().getObjects(door.class).size();f++){
                         d = (door) getWorld().getObjects(door.class).get(f);
                         d.open();
                  }
            }
        }
        
    }    
    
     
}
